{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Histograms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In a histogram, the height of each bar (bin) represents the number of data points that fall into its interval.\n",
    "They are generally used to show the distribution of a variable."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// Generate some random data\n",
    "\n",
    "Random random = new Random();\n",
    "data1 = [];\n",
    "data2 = [];\n",
    "\n",
    "(1..10000).each {\n",
    "  data1 << random.nextGaussian();\n",
    "  data2 << 2*random.nextGaussian() + 1.0;\n",
    "}\n",
    "print(data1[7])\n",
    "OutputCell.HIDDEN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram(data: data1, binCount: 25);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram(initWidth:800, initHeight:200,\n",
    "              title:\"Wide Histogram with Manual Parameters\",\n",
    "              xLabel:\"Size\",\n",
    "              yLabel:\"Count\",\n",
    "              rangeMin: -8, \n",
    "              rangeMax: 8, \n",
    "              data: data1 + [7]*200,\n",
    "              binCount: 99, \n",
    "              color: new Color(0, 154, 166));"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram(title:\"Default is Overlap\",\n",
    "              data: [data1, data2],\n",
    "              binCount: 99,\n",
    "              names: [\"old and tired\", \"new and improved\"],\n",
    "              color: [new Color(0, 154, 166),\n",
    "                      new Color(230, 50, 50, 128) // transparent!\n",
    "                     ]);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram(title:\"Stack\",\n",
    "              showLegend: false,\n",
    "              displayMode: Histogram.DisplayMode.STACK,\n",
    "              data: [data1, data2],\n",
    "              binCount: 99)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram(title:\"Side by Side\",\n",
    "              displayMode: Histogram.DisplayMode.SIDE_BY_SIDE,\n",
    "              data: [data1,data2], \n",
    "              binCount: 55)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram(title:\"Cumulative\",\n",
    "              cumulative: true,\n",
    "              data: data1,\n",
    "              binCount: 55);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In a *normed* histogram, the height of the bars is scaled so the area under the histogram is unity."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram(title:\"Normed, Area = 1.0\",\n",
    "              normed: true,\n",
    "              data: data1,\n",
    "              binCount: 55);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram(log: true,  \n",
    "              data: data1,\n",
    "              binCount: 99);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "beakerx_kernel_parameters": {},
  "kernelspec": {
   "display_name": "Groovy",
   "language": "groovy",
   "name": "groovy"
  },
  "language_info": {
   "codemirror_mode": "groovy",
   "file_extension": ".groovy",
   "mimetype": "",
   "name": "Groovy",
   "nbconverter_exporter": "",
   "version": "2.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
